const numbers1 = []; //天
for (let i = 1; i <= 365; i++) {
  numbers1.push(i)
}
const numbers2 = []; //月
for (let i = 1; i <= 23; i++) {
  numbers2.push(i)
}
const numbers3 = []; //年
for (let i = 1; i <= 1; i++) {
  numbers3.push(i)
}

Page({
  data: {
    numbers: numbers1,
    number: 1,
    units: ['天', '月', '年', ],
    unit: '天',
    value: [0, 0],
  },
  onLoad(){
    console.log('pro', this.properties)
  },
  bindChange: function(e) {
    const val = e.detail.value
    if (this.data.unit !== this.data.units[val[1]]) {
      if (this.data.units[val[1]] === '月') {
        this.setData({
          value: [0, 1],
          numbers: numbers2,
          unit: '月',
          number: 1
        })
      } else if (this.data.units[val[1]] === '年') {
        this.setData({
          value: [0, 2],
          numbers: numbers3,
          unit: '年',
          number: 1
        })
      } else {
        this.setData({
          value: [0, 0],
          numbers: numbers1,
          unit: '天',
          number: 1
        })
      }
    } else {
      this.setData({
        number: this.data.numbers[val[0]],
        unit: this.data.units[val[1]]
      });
    }

    //传送数据
    const myEventDetail = {
      // number: this.data.numbers[val[0]],//不知道为啥这个在2天到1年的时候会传NaN，有空研究一下
      // unit: this.data.units[val[1]]
      number:this.data.number,
      unit: this.data.unit
    } // detail对象，提供给事件监听函数
    const myEventOption = {} // 触发事件的选项
    this.triggerEvent('subevent', myEventDetail, myEventOption)
  }
})